package cn.leaves.wb.db.dao.jdbc;

import java.sql.SQLException;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

public class BaseJDBC {
	protected JdbcTemplate jdbcTemplate;

	@Autowired
	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	
	protected void save(Object instance, String... reflusedProperties) throws SQLException {
		try {
			SQLGenerator generator = new SQLGenerator(instance, reflusedProperties);
			jdbcTemplate.update(generator.buildInsertSql(), generator.getValues());
		} catch (Exception e) {
			throw new SQLException("generator sql failed", e);
		}
	}

}
